#coding=utf-8
#二分检索并确定在哪个位置

def binary_search(list_: list, item):
    n = len(list_)
    if n < 1:
        return False
    left = 0
    right = n - 1
    mid = (left + right) // 2
    if list_[mid] == item:
        return mid
    elif item < list_[mid]:
        newList = list_[0:mid]
        newResult=binary_search(newList,item)
        if newResult is False:
            return False
        else:
            return binary_search(newList, item)
    elif item > list_[mid]:
        newList = list_[mid+1:]
        newResult=binary_search(newList,item)
        if newResult is False:
            return False
        else:
            return mid + binary_search(newList, item) + 1

if __name__ == '__main__':
    list_ = [9, 11, 33, 36, 48, 52, 74, 87]
    for item in [7,9,11,33,36,37,48,52,74,87,88,100]:
        result = binary_search(list_, item)
        print(result)